<template>
  <div style="height: 100%; width: 100%; position: relative; overflow: hidden">
      <div class="page-top" style="border: 1px solid #ccc">
          <div style="width: 100%; height: 100%">
              <table style="width: 100%; font-size: 12px; border-spacing: 5px">
                  <tr>
                      <td width="60" align="right">标本日期</td>
                      <td width="160">
                          <el-date-picker v-model="s_sampledate" type="date" placeholder="选择日期" style="width: 160px" value-format="yyyy-MM-dd"></el-date-picker>
                      </td>
                      <td width="60" align="right">条码号</td>
                      <td width="160">
                          <el-input v-model="s_barcde" placeholder="请输入条码号" style="width: 100%" clearable></el-input>
                      </td>
                      <td width="60" align="right">病人号</td>
                      <td width="160">
                          <el-input v-model="s_pat_no" placeholder="请输入病人号" style="width: 100%" clearable></el-input>
                      </td>
                      <td width="60" align="right">病人姓名</td>
                      <td width="160">
                          <el-input v-model="s_pat_name" placeholder="请输入病人姓名" style="width: 100%" clearable></el-input>
                      </td>
                      <td width="60" align="right">身份证号</td>
                      <td width="160">
                          <el-input v-model="s_pat_idcardno" placeholder="请输入身份证号" style="width: 100%" clearable></el-input>
                      </td>
                      
                  </tr>
                  <tr>
                      <td colspan="12" align="left">
                          <div class="mychkclass">
                              &nbsp;&nbsp;
                              请选择要更新的信息
                              <el-checkbox true-label="1" false-label="0" v-model="chk_patname" style="margin-left: 5px">病人姓名</el-checkbox>
                              <el-checkbox true-label="1" false-label="0" v-model="chk_patsex">病人性别</el-checkbox>
                              <el-checkbox true-label="1" false-label="0" v-model="chk_patageyear">年龄岁数</el-checkbox>
                              <el-checkbox true-label="1" false-label="0" v-model="chk_patidcardno">身份证号</el-checkbox>
                              <el-checkbox true-label="1" false-label="0" v-model="chk_patphone">联系电话</el-checkbox>
                          </div>
                      </td>
                      <td width="500" align="right">
                          <el-button type="primary" @click="btnQuery" icon="el-icon-search">查询</el-button>
                          <el-button @click="btnClear" icon="el-icon-refresh-left">清除</el-button>
                          <el-button @click.native="btnUpdate" icon="el-icon-position">更新病人信息</el-button>
                          <!-- <el-button @click.native="btnUpName" icon="el-icon-position">更新病人姓名</el-button> -->
                      </td>
                  </tr>
              </table>
          </div>
      </div>
      <div class="pagecenter">
          <div style="height: 99%; width: 100%">
              <vxe-table ref="xTable" :data.sync="labReportList" :loading="labReportLoading" show-overflow height="auto" :select-config="{ reserve: true }" border size="mini" :mouse-config="{ selected: true }" show-header-overflow highlight-current-row header-align="center" resizable stripe :sort-config="{ trigger: 'cell' }">
                  <vxe-table-column type="selection" width="45px" align="center"></vxe-table-column>
                  <vxe-table-column field="reportid" title="报告ID" width="120px" header-align="center" align="left" sortable></vxe-table-column>
                  <vxe-table-column field="sampledate" title="标本日期" :formatter="['toDateString', 'yyyy-MM-dd']" width="100px" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="sampleno" title="标本编号" width="100px" sortable></vxe-table-column>
                  <vxe-table-column field="pat_no" title="病人号" width="100px" sortable></vxe-table-column>
                  <vxe-table-column field="pat_name" title="病人姓名" width="80px" sortable></vxe-table-column>
                  <vxe-table-column field="pat_sexname" title="性别" width="60px" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="pat_ageyear" title="年龄岁数" width="60px" sortable></vxe-table-column>
                  <vxe-table-column field="pat_idcardno" title="身份证号" width="160px"></vxe-table-column>
                  <vxe-table-column field="pat_phone" title="联系电话" width="100px"></vxe-table-column>
                  <vxe-table-column field="pat_typecodename" title="病人类别" width="100px" sortable></vxe-table-column>
                  <vxe-table-column field="pat_id" title="病人ID" width="100px"></vxe-table-column>
                  <vxe-table-column field="inp_id" title="住院标识" width="65px"></vxe-table-column>
                  <vxe-table-column field="specimen_codename" title="标本类型" width="120px" sortable></vxe-table-column>
                  <vxe-table-column field="sampled_dt" title="采样时间" width="133" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="rechkflagname" title="审核状态" width="80px" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="pat_diag_icd" title="诊断Icd10" width="100px"></vxe-table-column>
                  <vxe-table-column field="report_commname" title="报告备注" width="120px"></vxe-table-column>
                  <vxe-table-column field="lab_advice" title="实验意见" width="120px"></vxe-table-column>
                  <vxe-table-column field="barcode" title="条码号" width="120px"></vxe-table-column>
                  <vxe-table-column field="report_username" title="检验者" width="80px"></vxe-table-column>
                  <vxe-table-column field="rechk_username" title="审核者" width="100px"></vxe-table-column>
                  <vxe-table-column field="charge_typenoname" title="收费类别" width="70px"></vxe-table-column>
                  <vxe-table-column field="req_deptnoname" title="申请科室" width="120px"></vxe-table-column>
                  <vxe-table-column field="req_wardnoname" title="病人病区" width="100px"></vxe-table-column>
                  <vxe-table-column field="req_docnoname" title="申请医生" width="120px"></vxe-table-column>
                  <vxe-table-column field="req_bedno" title="床号" width="80px"></vxe-table-column>
                  <vxe-table-column field="pat_diagname" title="临床诊断" width="120px"></vxe-table-column>
              </vxe-table>
          </div>
      </div>

      <el-dialog title="提示" :visible.sync="msgdialog" width="50%" style="overflow: hidden !important">
          <div style="height: 300px; overflow-y: scroll">
              <div v-html="showmsg" ></div>
          </div>
          <div style="text-align: center">
              <span slot="footer" class="dialog-footer">
                  <el-button @click="msgdialog = false">取 消</el-button>
              </span>
          </div>
      </el-dialog>
  </div>
</template>

<script>
import XEUtils from "xe-utils";
export default {
  name: "LIS327",
  data() {
      return {
          s_sampledate: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
          s_barcde: "",
          s_pat_no: "",
          s_pat_name: "",
          s_pat_idcardno: "",
          labReportList: [],
          labReportLoading: false,
          showmsg: "",
          msgdialog: false,
          //更新病人信息
          chk_patname:"1",
          chk_patsex:"1",
          chk_patageyear:"1",
          chk_patidcardno:"1",
          chk_patphone:"1",

      };
  },
  mounted() {},
  methods: {
      btnQuery() {
          this.labReportLoading = true;
          this.labReportList = [];
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS327",
                  method: "post",
                  data: {
                      action: "querylabreport",
                      sampledate: this.s_sampledate,
                      barcde: this.s_barcde,
                      pat_no: this.s_pat_no,
                      pat_name: this.s_pat_name,
                      pat_idcardno: this.s_pat_idcardno,
                  },
              })
              .then((response) => {
                  this.labReportList = response.Data;
                  this.labReportLoading = false;
              });
      },
      btnUpName(){
          let list = this.$refs.xTable.getSelectRecords();
          if (list.length == 0) {
              this.$alert("请选择要更新的数据！");
              return false;
          }
          if(list.length > 1){
              this.$alert("无法选择多条数据更新病人姓名");
              return false;
          }
          this.$prompt("", "更新病人姓名", {
                      confirmButtonText: "确定",
                      cancelButtonText: "取消",
                      showCancelButton: true,
                      cancelButtonClass: "el-button el-button--default el-button--small el-button--primary",
                      confirmButtonClass: "el-button el-button--default el-button--small",
                      focusCancelButton: false,
                      inputValue: list[0].pat_name,
                  }).then(({ value }) => {
                      if(value==""){
                          this.$alert("病人姓名不能为空！");
                          return false;
                      }
                       this.$tool
                          .request({
                              url: "LIS/LIS3/LIS327",
                              method: "post",
                              data: {
                                  action: "updatename",
                                  reportid:list[0].reportid,
                                  pat_name:value,
                              },
                          })
                          .then(res=>{
                              if(res.errcode=="1"){
                                  list[0].pat_name=value;
                                  this.$alert("更新成功","提示");
                                  
                              }else{
                                  this.$alert(res.errmsg,"提示");
                              }
                          })  
                          .catch(err => {});
                      })
                  .catch(e =>{});

      },
      // 更新病人信息
      async btnUpdate() {
          let list = this.$refs.xTable.getSelectRecords();
          if (list.length == 0) {
              this.$alert("请选择要更新的数据！");
              return false;
          }
          if(this.chk_patname=="0" && this.chk_patsex=="0" && this.chk_patageyear=="0" && this.chk_patidcardno=="0" && this.chk_patphone=="0" ){
              this.$alert("请选择要更新的病人的信息！");
              return false;
          }
          var chkdata={
              chk_patname:this.chk_patname,
              chk_patsex:this.chk_patsex,
              chk_patageyear:this.chk_patageyear,
              chk_patidcardno:this.chk_patidcardno,
              chk_patphone:this.chk_patphone
              };
          let istrue = true;
          for (const element of list) {
              let errrormsg = "";

              const res = await this.$tool.request({
                  url: "LIS/LIS3/LIS327",
                  method: "post",
                  data: {
                      action: "updatepat",
                      reportinfo: element,
                      chkdata:chkdata,
                  },
              });
              switch (res.flag) {
                  case "1":
                      errrormsg += "【" + element.reportid + "】  更新完成" + "\n";
                      element.pat_name = res.labreport.pat_name;
                      element.pat_sex = res.labreport.pat_sex;
                      if (res.labreport.pat_sex == "1") {
                          element.pat_sexname = "男";
                      } else if (res.labreport.pat_sex == "2") {
                          element.pat_sexname = "女";
                      } else {
                          element.pat_sexname = "未知";
                      }
                      element.pat_ageyear = res.labreport.pat_ageyear;
                      element.pat_idcardno = res.labreport.pat_idcardno;
                      element.pat_phone = res.labreport.pat_phone;

                      this.$message.success(errrormsg);
                      break;
                  case "99":
                      //
                      this.checkCaLogin(element.rechk_user).then((cares) => {
                          if (cares.flag == "1") {
                              // 执行接下来的修改任务
                              this.$tool
                                  .request({
                                      url: "LIS/LIS3/LIS327",
                                      method: "post",
                                      data: {
                                          action: "updaterechkreport",
                                          reportinfo: res.labreport,
                                          strsql: res.strsql,
                                          
                                      },
                                  })
                                  .then((res1) => {
                                      if (res1.flag == -1) {
                                          // this.rcvmsgfault("【" + element.reportid + "】" + res.msg);
                                          errrormsg = "【" + element.reportid + "】" + res1.msg + "\n";
                                          this.$alert(errrormsg, "提示", {
                                              confirmButtonText: "确定",
                                              type: "error",
                                          });
                                      } else {
                                          element.pat_name = res.labreport.pat_name;
                                          element.pat_sex = res.labreport.pat_sex;
                                          if (res.labreport.pat_sex == "1") {
                                              element.pat_sexname = "男";
                                          } else if (res.labreport.pat_sex == "2") {
                                              element.pat_sexname = "女";
                                          } else {
                                              element.pat_sexname = "未知";
                                          }
                                          element.pat_ageyear = res.labreport.pat_ageyear;
                                          element.pat_idcardno = res.labreport.pat_idcardno;
                                          element.pat_phone = res.labreport.pat_phone;
                                          errrormsg = "【" + element.reportid + "】  更新完成";

                                          this.$message.success(errrormsg);
                                      }
                                  })
                                  .catch((e) => {});
                          } else {
                              this.$alert("CA登录失败！" + cares.msg, "登陆失败", {
                                  confirmButtonText: "确定",
                                  type: "error",
                              });
                          }
                      });
                      break;
                  case "-1":
                      istrue = false;
                      errrormsg = "【" + element.reportid + "】" + res.msg + "\n";
                      break;
                  default:
                      // errrormsg = "【" + element.reportid + "】" + res.msg + "\n";
                      // this.$message.warning(errrormsg);
                      break;
              }
              if (!istrue) {
                  this.$alert(errrormsg, "提示", {
                      confirmButtonText: "确定",
                      type: "error",
                  });
                  break;
              }
          }
      },

      //CA认证
      checkCaLogin(rckuser) {
          return new Promise((s, f) => {
              if (this.useca == "1") {
                  this.$ca.checklogin("rptchk", rckuser).then((cares) => {
                      s(cares);
                  });
              } else {
                  s({ flag: "1" });
              }
          });
      },
      // 清除 按钮
      btnClear() {
          this.s_sampledate = XEUtils.toDateString(new Date(), "yyyy-MM-dd");
          this.s_barcde = "";
          this.s_pat_no = "";
          this.s_pat_name = "";
          this.s_pat_idcardno = "";
          this.labReportList = [];
      },
  },
};
</script>

<style scoped>
.page-top {
  left: 0;
  right: 0;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  border: solid 1px #ccc;
  position: absolute;
  z-index: 99;
  overflow-x: auto;
  overflow-x: overlay;
  margin: 0;
  padding: 0;
  white-space: nowrap;
}
::-webkit-scrollbar {
  width: 0px;
  height: 5px;
  border: 4px solid white;
}
::-webkit-scrollbar-thumb {
  background-color: #c1c1c1;
}
::-webkit-scrollbar-track {
  background-color: #f1f1f1;
}
/* Buttons */
::-webkit-scrollbar-button:single-button {
  background-color: #bbbbbb;
  display: block;
  border-style: solid;
  height: 5px;
  width: 5px;
}
/* Left */
::-webkit-scrollbar-button:horizontal:decrement {
  margin-right: 2px;
  border-width: 4px 4px 4px 0;
  border-color: #f1f1f1 transparent #f1f1f1 #f1f1f1;
  background-color: #000000;
}
::-webkit-scrollbar-button:horizontal:decrement:hover {
  border-color: #d2d2d2 transparent #d2d2d2 #d2d2d2;
}
/* Right */
::-webkit-scrollbar-button:horizontal:increment {
  margin-left: 2px;
  border-width: 4px 0 4px 4px;
  border-color: #f1f1f1 #f1f1f1 #f1f1f1 transparent;
  background-color: #000000;
}
::-webkit-scrollbar-button:horizontal:increment:hover {
  border-color: #d2d2d2 #d2d2d2 #d2d2d2 transparent;
}
/deep/ .page-top .el-select {
  width: 160px !important;
}
.pagecenter {
  position: absolute;
  top: 70px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}
.dialog-button {
  margin-top: 10px;
  text-align: center;
  display: flex;
  justify-content: flex-end;
}
/deep/ .el-radio-group {
  width: 100%;
  display: flex;
  justify-content: space-around;
}
/deep/ .dialog-textarea .el-textarea__inner {
  height: 100%;
}
/deep/ .mychkclass .el-checkbox {
  margin-right: 15px;
}
</style>